package com.mz.ozy.activity.home;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.mz.ozy.R;
import com.mz.ozy.adapter.CardVoucherAdapter;
import com.mz.ozy.adapter.RecyclerViewAdapter;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.BalanceDetailBean;
import com.mz.ozy.bean.ExchangeOrderBean;
import com.mz.ozy.mvp.presenter.BalanceDetailPresenter;
import com.mz.ozy.mvp.view.BalanceDetailContract;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class RedeemVoucherActivity1 extends BaseActivity<BalanceDetailContract.View, BalanceDetailPresenter> implements BalanceDetailContract.View {

    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R.id.ll_no_data)
    LinearLayout llNoData;
    private CardVoucherAdapter mCardVoucherAdapter;
    private String mPrice;
    private String mGname;
    private int mPosition;
    private List<ExchangeOrderBean.CardMapBean> mCardList;

    public static void go(Activity context, List<ExchangeOrderBean.CardMapBean> bean, int position, String price, String gname) {
        Intent intent = new Intent(context, RedeemVoucherActivity1.class);
        intent.putExtra("bean", (Serializable) bean);
        intent.putExtra("position", position);
        intent.putExtra("price", price);
        intent.putExtra("gname", gname);
        context.startActivityForResult(intent, 1002);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_redeem_voucher);
        ButterKnife.bind(this);
        initTitle();
        mPosition = getIntent().getIntExtra("position", 0);
        mPrice = getIntent().getStringExtra("price");
        mGname = getIntent().getStringExtra("gname");
        mCardList = (List<ExchangeOrderBean.CardMapBean>) getIntent().getSerializableExtra("bean");
        tvCenterTitle.setText("兑换券列表");
        tvTitle.setVisibility(View.GONE);
        llNoData.setVisibility(View.GONE);
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        mCardVoucherAdapter = new CardVoucherAdapter(this, mCardList, mPrice, mGname, mPosition);
        recyclerview.setAdapter(mCardVoucherAdapter);
        mCardVoucherAdapter.setOnItemClickListener(new RecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position, Object dataItem) {
                if (position == mCardVoucherAdapter.getSelectPosition()) {
                    mCardVoucherAdapter.setSelectPosition(-1);
                } else {
                    mCardVoucherAdapter.setSelectPosition(position);
                }
            }

            @Override
            public void onItemLongClick(View view, int position, Object dataItem) {

            }
        });
    }

    @OnClick({R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_confirm://抵扣
                Intent intent = new Intent();
                intent.putExtra("pos", mCardVoucherAdapter.getSelectPosition());
                setResult(RESULT_OK, intent);
                finish();
                break;
        }
    }

    @Override
    public void getBalanceDetailSuccess(BalanceDetailBean bean) {
//        if (tag == 0) {
//            smartRefreshLayout.setLoadmoreFinished(false);
//            smartRefreshLayout.finishRefresh();
//            mBeanList.clear();
//            if (bean.getPage().getPageItems().size() == 0) {
//                llNoData.setVisibility(View.VISIBLE);
//            } else {
//                llNoData.setVisibility(View.GONE);
//            }
//
//        } else if (tag == 1) {
//            smartRefreshLayout.finishLoadmore();
//        }
//        mBeanList.addAll(bean.getPage().getPageItems());
//        mBalanceDetailAdapter.notifyDataSetChanged();
//        if (bean.getPage().getPageItems().size() == 0 || bean.getPage().getPageSize() * bean.getPage().getPageNumber() >= bean.getPage().getPageTotle()) {
//            smartRefreshLayout.setLoadmoreFinished(true);//将不会再次触发加载更多事件
//        }
    }

}
